<template>
  <div>
    <el-dialog
      v-model="store.state.HomeModule.dialogFormVisible"
      title="修改车位信息"
    >
      <el-form :model="form">
        <el-form-item label="车牌号码" :label-width="formLabelWidth">
          <el-input
            v-model="form.Carnum"
            autocomplete="off"
            placeholder="车牌号码"
          />
        </el-form-item>
        <el-form-item label="司机姓名" :label-width="formLabelWidth">
          <el-input
            v-model="form.Driver"
            autocomplete="off"
            placeholder="姓名"
          />
        </el-form-item>
        <el-form-item label="负责人" :label-width="formLabelWidth">
          <el-input
            v-model="form.Charge"
            autocomplete="off"
            placeholder="负责人"
          />
        </el-form-item>
        <el-form-item label="汽车品牌" :label-width="formLabelWidth">
          <el-input
            v-model="form.Brand"
            autocomplete="off"
            placeholder="品牌"
          />
        </el-form-item>
        <el-form-item label="汽车型号" :label-width="formLabelWidth">
          <el-input v-model="form.Kind" autocomplete="off" placeholder="型号" />
        </el-form-item>
        <el-form-item label="汽车用途" :label-width="formLabelWidth">
          <el-input
            v-model="form.Doing"
            autocomplete="off"
            placeholder="用途"
          />
        </el-form-item>
        <el-form-item label="购车地点" :label-width="formLabelWidth">
          <el-input
            v-model="form.Buyplace"
            autocomplete="off"
            placeholder="购车地点"
          />
        </el-form-item>
        <el-form-item label="资产原值" :label-width="formLabelWidth">
          <el-input
            v-model="form.Worthpast"
            autocomplete="off"
            placeholder="资产原值"
          />
        </el-form-item>
        <el-form-item label="资产现值" :label-width="formLabelWidth">
          <el-input
            v-model="form.Worthnow"
            autocomplete="off"
            placeholder="资产现值"
          />
        </el-form-item>
        <el-form-item label="备注" :label-width="formLabelWidth">
          <el-input
            v-model="form.Remark"
            autocomplete="off"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="closeDialog(0)">放弃更改</el-button>
          <el-button type="primary" @click="closeDialog(1)">
            提交更改
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import { useStore } from "vuex";
import link from "@/api/link.js";
import apiUrl from "@/api/url.js";
import { ElLoading } from "element-plus";
let store = useStore();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const fullscreenLoading = ref(false);
const closeDialog = (num: number) => {
  //提交更改
  if (num === 1) {
    store.commit("DIALOG");
    let datas = {
      Carnum: form.Carnum,
      Driver: form.Driver,
      Charge: form.Charge,
      Brand: form.Brand,
      Kind: form.Kind,
      Doing: form.Doing,
      Buyplace: form.Buyplace,
      Worthpast: form.Worthpast,
      Worthnow: form.Worthnow,
      Remark: form.Remark,
    };
    link(
      apiUrl.CompanyVehicles + "/" + store.state.HomeModule.uplistData.id,
      "PUT",
      datas
    ).then((resolve: any) => {
      console.log(resolve);
    });
    //转圈圈
    const loading = ElLoading.service({
      lock: true,
      text: "正在提交更改",
      background: "rgba(0, 0, 0, 0.7)",
    });
    setTimeout(() => {
      loading.close();
    }, 1000);
  } else {
    //放弃更改
    store.commit("DIALOG");
  }
};
//表单宽度
const formLabelWidth = "200px";
//表单数据
const form = reactive({
  Carnum: "",
  Driver: "",
  Charge: "",
  Brand: "",
  Kind: "",
  Doing: "",
  Buyplace: "",
  Worthpast: "",
  Worthnow: "",
  Remark: "",
});
</script>
<style scoped>
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
